home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Essentials / MacApp Documentation / MacApp.TECH$ Archives / 1991 / Jan 91 / MacApp.Tech$ 1⁄18⁄91 / 2718-TAspectPicture x 2-Jan91 < prev    next >
Encoding:
Text File  |  1991-03-06  |  3.3 KB  |  114 lines  |  [TEXT/GEOL]

  1. Item    5976813                         18-Jan-91        05:17PST
  2.  
  3. From:   AUST0134                        Jam Software Sydney,IVR
  4.  
  5. To:     POWERUP.DEV                     Power Up Software,PRT
  6.  
  7. cc:     MACAPP.TECH$                    MacApp Technical
  8.  
  9. ------------------------------------------------------------------------------
  10.  
  11. Sub:    TAspectPicture x 2
  12.  
  13. Here are two attempts at centering pictures within TPicture.
  14.  
  15. The first one OVERRIDEs TPicture.Draw, and has no other effect than just to
  16. draw the picture in its original picFrame, centred within TPicture.
  17.  
  18. The second one OVERRIDEs TControl.ControlArea, and so not only does the picture
  19. draw itself in the centre of the TPicture, mouseclicks will only count if they
  20. occur in the centred picture frame as well.
  21.  
  22. CentreRectInRect is just a bonus utility which does what it says.
  23.  
  24. PROCEDURE CenterRectInRect(VAR inner: Rect; outer: Rect; horiz, vert: Boolean);
  25. { centre the inner rect within the outer rect, either horizontally, or
  26. vertically, or both
  27. }
  28. VAR
  29.    innerSize, outerSize:   Point;
  30. BEGIN
  31.    WITH outer DO
  32.    SetPt(outerSize, right - left, bottom - top);
  33.    WITH inner DO BEGIN
  34.    SetPt(innerSize, right - left, bottom - top);
  35.    IF horiz THEN
  36.    left := outer.left + (outerSize.h - innerSize.h) DIV 2;
  37.    IF vert THEN
  38.    top := outer.top + (outerSize.v - innerSize.v) DIV 2;
  39.    right := left + innerSize.h;
  40.    bottom := top + innerSize.v;
  41.    END;
  42. END;
  43.  
  44. {-----------------------
  45.       version 1
  46. ------------------------}
  47. TYPE
  48.    TAspectPicture = OBJECT(TPicture)
  49.    PROCEDURE Draw(area: Rect); OVERRIDE;
  50.    END;
  51.  
  52. PROCEDURE TAspectPicture.Draw(area: Rect); OVERRIDE;
  53. {  Modified from TPicture.Draw just to grab the actual picture frame, and
  54.    then centre this frame within the TPicture area before drawing it
  55. }
  56. VAR
  57.    oldState:   SignedByte;
  58.    cntlFrame,
  59.    myPicFrame: Rect;
  60.    saveDataHandle: picHandle;
  61. BEGIN
  62.    IF fDataHandle <> NIL THEN BEGIN
  63.    IF fRsrcID <> kNoResource THEN
  64.    LoadResource(Handle(fDataHandle));
  65.    IF fDataHandle^ <> NIL THEN BEGIN   { If there's room for the picture… }
  66.    ControlArea(cntlFrame);
  67.    myPicFrame := fDataHandle^^.picFrame;
  68.    CenterRectInRect(myPicFrame,cntlFrame,TRUE,TRUE);
  69.    oldState := GetHandleBits(Handle(fDataHandle));
  70.    HNoPurge(Handle(fDataHandle));
  71.    PenNormal;
  72.    DrawPicture(fDataHandle, myPicFrame);
  73.    SetHandleBits(Handle(fDataHandle), oldState);
  74.    END;
  75.    END;
  76.    saveDataHandle := fDataHandle;
  77.    fDataHandle := NIL;
  78.    INHERITED Draw(area);
  79.    fDataHandle := saveDataHandle;
  80. END;
  81.  
  82. {-----------------------
  83.       version 2
  84. ------------------------}
  85. TYPE
  86.    TAspectPicture = OBJECT(TPicture)
  87.    PROCEDURE ControlArea(VAR theArea: Rect); OVERRIDE;
  88.    END;
  89.  
  90. PROCEDURE TAspectPicture.ControlArea(VAR theArea: Rect); OVERRIDE;
  91. {  Change the control area to just be the area of the original picFrame of
  92.    the picture, centered within the TPicture control area.
  93. }
  94. VAR
  95.    myPicFrame: Rect;
  96. BEGIN
  97.    INHERITED ControlArea(theArea);
  98.  
  99.    IF fDataHandle <> NIL THEN BEGIN
  100.    IF fRsrcID <> kNoResource THEN
  101.    LoadResource(Handle(fDataHandle));
  102.    IF fDataHandle^ <> NIL THEN BEGIN   { If there's room for the picture… }
  103.    myPicFrame := fDataHandle^^.picFrame;
  104.    CenterRectInRect(myPicFrame,theArea,TRUE,TRUE);
  105.    theArea := myPicFrame;
  106.    END;
  107.    END;
  108. END;
  109.  
  110. Tseung Cheung
  111. JAM Software Pty Ltd
  112. ALink AUST0134
  113.  
  114.